package cn.tedu.smartos.notice.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.base.response.StatusCode;
import cn.tedu.smartos.notice.pojo.vo.ActivityNoticeVO;
import cn.tedu.smartos.notice.pojo.vo.SystemNoticeVO;
import cn.tedu.smartos.notice.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "04.通知模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/notices")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation("获取系统通知")
    @GetMapping("/system")
    public JsonResult getSystemNotices(@RequestParam Long userId) {
        log.debug("开始处理【获取系统通知】的请求,参数:{}", userId);
        List<SystemNoticeVO> notices = noticeService.getSystemNotices(userId);
        return new JsonResult(StatusCode.SUCCESS, notices);
    }

    @ApiOperation("获取活动通知")
    @GetMapping("/activity")
    public JsonResult getActivityNotices(@RequestParam Long userId) {
        log.debug("开始处理【获取活动通知】的请求,参数:{}", userId);
        List<ActivityNoticeVO> notices = noticeService.getActivityNotices(userId);
        return new JsonResult(StatusCode.SUCCESS, notices);
    }

    @ApiOperation("标记通知为已读")
    @PostMapping("/markRead")
    public JsonResult markNoticeAsRead(
            @RequestParam Long userId,
            @RequestParam Long noticeId) {
        log.debug("开始处理【标记通知为已读】的请求,参数:{},{}", userId, noticeId);
        noticeService.markNoticeAsRead(userId, noticeId);
        return JsonResult.ok();
    }
}